#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int num[N];
int t,n,a[N],sum;
int maxn=1;
int c[N];
void fun(int deep){
    if(deep>n){
            int num=0;
        for(int i=n;i>=2;i--){
        int x=i-1;
        while(c[x]!=c[i])x--;
            if(a[x]==a[i]){
                    num+=a[i];
                    //cout<<i<<" ";
            }
        }
        sum=max(sum,num);
    }else{
    c[deep]=1;
    fun(deep+1);
    c[deep]=2;
    fun(deep+1);
    return;
    }
}
int main(){
freopen("color.in","r",stdin);
freopen("color.out","w",stdout);
cin>>t;
for(int z=1;z<=t;z++){
        cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
    sum=0;
    fun(0);
cout<<sum<<endl;
}
return 0;
}//
